<?php
	
	function pushNotification($deviceToken, $message, $badge) {
		$mode = "product";
		$body = array("aps" => array("alert" => $message, "sound"=>'default'));
  
		$ctx = stream_context_create();
		$fp;
		if($mode == "development")
		{
			stream_context_set_option($ctx, "ssl", "local_cert", "apns_dev.pem");
			$fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
		}
		else
		{
			stream_context_set_option($ctx, "ssl", "local_cert", "apns_pro.pem");
			$fp = stream_socket_client("ssl://gateway.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
		}
		
		stream_context_set_option($ctx, "ssl", "passphrase", "123123");
		if (!$fp) {
			return;
		}
		
		
		$payload = json_encode($body);
		$msg = chr(0) . pack("n",32) . pack("H*", str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
		fwrite($fp, $msg);
		fclose($fp);
		}

?>

